﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using MKAdminCore.Controllers;
using MKAdminCore.DTO.CusAttribute;
using MKAdminCore.DTO.Web.BasicSetting;
using MKAdminCore.DTO.Web.Common;
using MKAdminCore.IService.Web.BasicSetting;
using MKAdminCore.ToolKit.Config;

namespace MKAdminCore.Areas.BasicSetting.Controllers
{
    [Area("BasicSetting")]
    [Route("BasicSetting/[controller]/[action]")]
    public class RoleInfoController : BaseMvcController
    {
        private IRoleInfoService _iRoleInfoService;

        public RoleInfoController(IRoleInfoService iRoleInfoService)
        {
            _iRoleInfoService = iRoleInfoService;
        }

        public IActionResult Index()
        {
            return View(PageViewFilesConfig.BasicSettingRoleInfo);
        }

        [HttpPost]
        public IActionResult List(GetRoleInfoListParameter parameter)
        {
            var result = _iRoleInfoService.List(parameter);

            return Ok(result);
        }

        [HttpPost]
        public async Task<IActionResult> Add(OperatorRoleInfoAddParam parameter)
        {
            var result = new HttpResponseResult();
            var validateResult = parameter.Validate();
            if (validateResult.Code != 200)
            {
                result.Msg = validateResult.Msg;
                result.Code = validateResult.Code;
                return Ok(result);
            }

            var userInfo = base.GetUserInfo();
            result = await _iRoleInfoService.Add(parameter, userInfo);

            return Ok(result);
        }

        [HttpPost]
        public async Task<IActionResult> Edit(OperatorRoleInfoEditParam parameter)
        {
            var result = new HttpResponseResult();
            var validateResult = parameter.Validate();
            if (validateResult.Code != 200)
            {
                result.Msg = validateResult.Msg;
                result.Code = validateResult.Code;
                return Ok(result);
            }

            var userInfo = base.GetUserInfo();
            result = await _iRoleInfoService.Edit(parameter, userInfo);

            return Ok(result);
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="parameter"></param>
        /// <param name="userInfo"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> Del(OperatorRoleInfoDelParam parameter)
        {
            var result = new HttpResponseResult();
            var validateResult = parameter.Validate();
            if (validateResult.Code != 200)
            {
                result.Msg = validateResult.Msg;
                result.Code = validateResult.Code;
                return Ok(result);
            }

            var userInfo = base.GetUserInfo();
            result = await _iRoleInfoService.Del(parameter, userInfo);

            return Ok(result);
        }

        /// <summary>
        /// 获取角色权限集合
        /// </summary>
        /// <param name="parameter"></param>
        /// <param name="userInfo"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> GetRight(OperatorRoleInfoGetRight parameter)
        {
            var result = new HttpResponseResult();
            var validateResult = parameter.Validate();
            if (validateResult.Code != 200)
            {
                result.Msg = validateResult.Msg;
                result.Code = validateResult.Code;
                return Ok(result);
            }

            result = await _iRoleInfoService.GetRight(parameter);

            return Ok(result);
        }
        
    }
}